import Vue from 'vue'
let BASE_URL;
if(process.env.NODE_ENV == 'production'){
  if(location.pathname == '/activity-pages/tttt/sticker/pages/'){
    BASE_URL = 'https://st.gd10010.cn/relycube/tttt/sticker'
  }else{
    BASE_URL = 'https://st.gd10010.cn/relycube/sticker'   //   正式
  }
}else{
  BASE_URL = ''
}
export {BASE_URL}


export const get = async (url, params, load, config = {}) =>{
  return await new Promise((resolve,reject)=>{
    uni.request({
      url: BASE_URL + url,
      data: params,
      timeout: 80000,
      method: 'GET',
      header: {
        ...config
      },
      success: res => {
        console.log('请求成功',res.data)
        const {code} = res.data
        resolve(res.data)
        /** end 处理结束*/
      },
      fail: error => {
        reject(error)
      },
      complete:res=>{
        if(load) uni.hideLoading();
      }
    })
  })
}


export const post = async (url, params, load, config = {}) =>{
  return await new Promise((resolve,reject)=>{
    uni.request({
      url: BASE_URL + url,
      data: params,
      timeout: 80000,
      method: 'POST',
      header: {
        ...config
      },
      success: res => {
        console.log('请求成功',res.data)
        const {code} = res.data
        if(code == 403){
          uni.showToast({
            title:res.data.msg,
            icon:'none'
          })
        }
        resolve(res.data)
        /** end 处理结束*/
      },
      fail: error => {
        reject(error)
      },
      complete:res=>{
        if(load) uni.hideLoading();
      }
    })
  })
}